package org.jeecg.modules.kuner.hirebase.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.K;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.kuner.collectionbase.service.IKrCollectionBaseService;
import org.jeecg.modules.kuner.hirebase.entity.KrHireBase;
import org.jeecg.modules.kuner.hirebase.service.IKrHireBaseService;
import org.jeecg.modules.kuner.hirebase.vo.KrHireDetailVO;
import org.jeecg.modules.kuner.hirebase.vo.KrHireVO;
import org.jeecg.modules.putil.KrStatic;
import org.jeecg.modules.putil.LoginUserUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Description: 招聘信息
 * @Author: Van.Planifolia
 * @Date: 2025-02-18
 * @Version: V1.0
 */
@Api(tags = "小程序-招聘信息")
@RestController
@RequestMapping("/api/krHireBase")
@Slf4j
public class KrHireBaseApiController extends JeecgController<KrHireBase, IKrHireBaseService> {

    @Resource
    private IKrHireBaseService hireBaseService;
    @Resource
    private LoginUserUtil loginUserUtil;

    /**
     * 发布或者修改一个岗位
     *
     * @param hireBase 被发布或者修改的岗位
     * @return 操作结果
     */
    @ApiOperation("发布或者修改一个岗位")
    @PostMapping("/modifyHire")
    public Result<KrHireBase> modifyHire(@RequestBody @Validated KrHireBase hireBase) {
        hireBaseService.modifyHire(hireBase);
        return Result.OK("修改成功！");
    }

    /**
     * 首页列表查询
     *
     * @param mixSearch  混合查询条件
     * @param money      金额
     * @param workCity   工作城市
     * @param type       类型
     * @param edu        学历
     * @param searchType 排序类型
     * @param pageNo     分页页码
     * @param pageSize   分页大小
     * @return 查询结果
     */
    @IgnoreAuth
    @GetMapping("/list")
    @ApiOperation(
            value = "首页列表查询",
            notes = "<h2>该接口可用于所有的招聘信息查询</h2> " +
                    "参数描述 " +
                    "mixSearch 关键字输入框查询" +
                    "money 薪资起始数值" +
                    "workCity 工作地点" +
                    "type 工作类型对应首页八个分类" +
                    "edu 学历" +
                    "1.首页列表查询<br>" +
                    "2.首页八个分类查询<br>"
    )
    public Result<IPage<KrHireVO>> list(
            String mixSearch,
            BigDecimal money,
            String workCity,
            String type,
            Integer edu,
            @RequestParam(defaultValue = "CREATE_TIME") KrStatic.SearchType searchType,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        IPage<KrHireVO> page = hireBaseService.mixSearch(mixSearch, money, searchType, type, edu, workCity, pageNo, pageSize);
        return Result.OK("查询成功！", page);
    }


    /**
     * 我的发布
     *
     * @param pageNo   分页页码
     * @param pageSize 分页大小
     * @return 查询结果
     */
    @GetMapping("/myPublish")
    @ApiOperation(
            value = "首页列表查询"
    )
    public Result<IPage<KrHireBase>> myPublish(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String status
    ) {
        IPage<KrHireBase> page = new Page<>(pageNo, pageSize);
        page = hireBaseService.page(page, new LambdaQueryWrapper<KrHireBase>().eq(KrHireBase::getStatus, status).eq(KrHireBase::getPublishUser, loginUserUtil.getLoginUser().getId()));
        return Result.OK("查询成功！", page);
    }


    /**
     * 查询详情
     *
     * @param id 工作ID
     * @return 查询结果
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("职位详情")
    public Result<KrHireDetailVO> detail(@PathVariable String id) {
        KrHireDetailVO hireDetailVO = hireBaseService.detail(id);
        return Result.OK("查询成功", hireDetailVO);
    }


    /**
     * 去收藏
     *
     * @param hireId 被收藏的职位id
     * @return 收藏结果
     */
    @GetMapping("/doCollection/{hireId}")
    @ApiOperation("去收藏")
    public Result<?> doCollection(@PathVariable String hireId) {
        hireBaseService.doCollection(hireId);
        return Result.OK("收藏成功！");
    }

    /**
     * 去收藏
     *
     * @param hireId 被收藏的职位id
     * @return 收藏结果
     */
    @GetMapping("/cancelCollection/{hireId}")
    @ApiOperation("取消收藏")
    public Result<?> cancelCollection(@PathVariable String hireId) {
        hireBaseService.cancelCollection(hireId);
        return Result.OK("取消成功！");
    }

}
